/**
 * Created by litch on 2017/8/8.
 */
export function GET(url) {
    return new Promise(function (resolve, reject) {
        const client = new XMLHttpRequest();
        client.open('get', url, true);
        client.onreadystatechange = function () {
            if(this.readyState !== 4){
                return;
            }
            if(this.status === 200){
                resolve(this.response);
            }else{
                reject(new Error(this.statusText));
            }
        };
        client.responseType='json';
        client.send();
    })
}
export function POST(url,param) {
    return new Promise(function (resolve, reject) {
        const client = new XMLHttpRequest();
        client.open('POST', url, true);
        client.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        client.onreadystatechange = function () {
            if(this.readyState !== 4){
                return;
            }
            if(this.status === 200){
                resolve(this.response);
            }else{
                reject(new Error(this.statusText));
            }
        };
        client.responseType='json';
        client.send(param);
    })
};